package com.gitee.zhanyao.codebase.java.webservice.server.config;

import com.gitee.zhanyao.codebase.java.webservice.server.service.HelloWS;
import com.gitee.zhanyao.codebase.java.webservice.server.service.impl.HelloWSImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;


@Configuration
public class WebServiceConfig {

    @Bean(name = "cxfServlet")
    public ServletRegistrationBean dispatcherServlet() {
        //发布服务名称
        return new ServletRegistrationBean(new CXFServlet(), "/service/*");
    }

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }

    @Bean
    public HelloWS helloWS() {
        return new HelloWSImpl();
    }

    @Bean
    public Endpoint endpoint() {
        //绑定要发布的服务
        EndpointImpl endpoint = new EndpointImpl(springBus(), helloWS());
        //显示要发布的名称，访问地址：http://127.0.0.1:8080/service/hello?wsdl
        endpoint.publish("/hello");
        return endpoint;
    }

}